package com.Adapters;


import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import com.Adapters.Items.ItemFollowers;
import com.Adapters.Items.ItemPost;
import com.Data.User;


public class FollowersAdapter extends ArrayAdapter<User> {

    private ArrayList<ItemPost> rows;

    public FollowersAdapter(Context context, int resource,
                int textViewResourceId) {

        super(context, resource, textViewResourceId);

        rows = new ArrayList<ItemPost>();

    }

    @Override
    public void add(User object) {

        rows.add(new ItemFollowers(LayoutInflater.from(getContext()), object, this));

    }

    @Override
    public void clear() {

        rows.clear();
    }

    @Override
    public int getCount() {

        return rows.size();
    }

    @Override
    public long getItemId(int position) {

        return rows.get(position).getPostId();
    }

    @Override
    public View getView(int position, View v, ViewGroup parent) {

        return rows.get(position).getView(v, position);
    }

    @Override
    public void remove(User object) {

        for (int i = 0; i < rows.size(); i++) {
            ItemPost p = rows.get(i);
            if (object.getID() == p.getPostId()) {
                rows.remove(i);
                notifyDataSetChanged();
            }
        }
        if (getCount() == 0) {
            //
        }

    }

}
